Page({
  onLoad(ev) {
    this.getPassport(ev.id)
  },
  async getPassport(id) {
    const { code, data } = await wx.http.get('/visitor/' + id)
    if (code !== 10000) return wx.utils.toast('获取二维码失败')
    this.setData({
      ...data,
    })
  },
  onShareAppMessage() {
    return {
      title: '查看通行证',
      path: '/visitor_pkg/pages/passport/index',
      imageUrl: 'https://enjoy-plus.oss-cn-beijing.aliyuncs.com/images/share_poster.png',
    }
  },
  async saveImage() {
    // 将网络路径转换为本地
    const { path } = await wx.getImageInfo({
      src: this.data.url,
    })
    // 将图片保存到本地相册
    wx.saveImageToPhotosAlbum({
      filePath: path,
    })
  },
})
